<?php

namespace App\Providers;

use App\Common\Providers\CommonProvider;
use App\Edu\Providers\EduProvider;
use App\ExcelData\Providers\ExcelDataProvider;
use App\Sys\Providers\SysProvider;
use App\User\Providers\UserProvider;
use Illuminate\Redis\RedisServiceProvider;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        \App\Events\ExampleEvent::class => [
            \App\Listeners\ExampleListener::class,
        ],
    ];
    //路由文件名
    protected $routes = 'routes.php';

    public function boot()
    {
        //自动载入路由
        $func = new \ReflectionClass(get_class($this));
        $path = str_replace($func->getShortName() . '.php', '', $func->getFileName());
        $routesFile = $path . '../' . $this->routes;
        if (file_exists($routesFile)) {
            require $routesFile;
        }
        if (!isset($this->app['blade.compiler'])) {
            $this->app['view'];
        }
        $this->registerComponent();
        parent::boot();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //注册redis服务
        $this->app->register(RedisServiceProvider::class);
        //注册userProvider
        $this->app->register(SysProvider::class);
        //注册CommonProvider
        $this->app->register(CommonProvider::class);
        //注册导出excel
        $this->app->register(ExcelDataProvider::class);
        $this->app->register(UserProvider::class);
        $this->app->register(EduProvider::class);
    }

    /**
     * 注册组件
     */
    protected function registerComponent() {

    }
}
